<template>
  <div class="t_body">
    <JfHeader :viewstyle="viewstyle"></JfHeader>
    <!-- 面包屑导航区域 -->
    <el-row style="padding-bottom: 20px">
      <el-col :span="16" :offset="4">
        <el-breadcrumb
          separator-class="el-icon-arrow-right"
          style="line-height: 50px; height: 50px"
        >
          <el-breadcrumb-item :to="{ path: '/index' }">首页</el-breadcrumb-item>
          <el-breadcrumb-item>订单列表</el-breadcrumb-item>
        </el-breadcrumb>

        <!-- 卡片视图区 -->
        <el-card>
          <el-row>
            <el-col>
              <!-- 订单列表数据 -->
              <el-table :data="orderlist" border stripe>
                <!-- 展开列 -->
                <el-table-column type="expand">
                  <template slot-scope="scope">
                    <el-row
                      :class="['bdbottom', i === 0 ? 'bdtop' : '', 'vcenter']"
                      v-for="(item, i) in scope.row.children"
                      :key="item.id"
                    >
                      <el-col :span="2">
                        <img
                          style="width: 50px; height: 50px; padding-top: 15px"
                          :src="
                            'http://42.194.142.165:8088/sharePath/' + item.image
                          "
                          alt=""
                        />
                      </el-col>
                      <el-col :span="4">
                        <div class="font_hidden" :title="item.title">
                          {{ item.title }}
                        </div>
                      </el-col>
                      <el-col :span="2">
                        <div class="">{{ item.price }}</div>
                      </el-col>
                      <el-col :span="4">
                        <el-input-number
                          v-model="item.count"
                          :min="item.count"
                          :max="item.count"
                          size="mini"
                          label="描述文字"
                        ></el-input-number>
                      </el-col>
                    </el-row>
                  </template>
                </el-table-column>
                <el-table-column type="index"></el-table-column>
                <el-table-column
                  label="订单编号"
                  prop="orderSn"
                  width="220px"
                ></el-table-column>
                <el-table-column
                  label="订单价格"
                  prop="payAmount"
                  width="120px"
                ></el-table-column>
                <el-table-column label="是否付款" prop="status" width="120px">
                  <template slot-scope="scope">
                    <el-tag v-if="scope.row.status === 0" type="warning"
                      >待付款</el-tag
                    >
                    <el-tag v-if="scope.row.status === 1" type="primary"
                      >待发货</el-tag
                    >
                    <el-tag v-if="scope.row.status === 2" type="success"
                      >已发货</el-tag
                    >
                    <el-tag v-if="scope.row.status === 3" type="success"
                      >已完成</el-tag
                    >
                    <el-tag v-if="scope.row.status === 4" type="success"
                      >已关闭</el-tag
                    >
                  </template>
                </el-table-column>
                <el-table-column label="下单时间" prop="time" width="170px">
                  <template slot-scope="scope">
                    {{ scope.row.time }}
                  </template>
                </el-table-column>
                <el-table-column label="付款" prop="status" width="120px">
                  <template slot-scope="scope">
                    <el-button
                      v-if="scope.row.status === 0"
                      @click="handlePay(scope.row.orderSn, scope.row.payAmount)"
                      type="primary"
                      size="mini"
                      icon="el-icon-edit"
                      >付款</el-button
                    >
                    <el-tag v-else type="primary">已付款</el-tag>
                  </template>
                </el-table-column>
                <el-table-column label="备注" prop="time" width="113px">
                  <template slot-scope="scope">
                    {{ scope.row.note }}
                  </template>
                </el-table-column>
              </el-table>
            </el-col>
          </el-row>

          <!-- 分页区域 -->
          <el-pagination
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="queryInfo.pagenum"
            :page-sizes="[5, 10, 15]"
            :page-size="queryInfo.pagesize"
            layout="total, sizes, prev, pager, next, jumper"
            :total="total"
            style="margin: 10px 0px"
          >
          </el-pagination>
        </el-card>
      </el-col>
    </el-row>
    <JfFooter></JfFooter>
  </div>
</template>

<script>
import JfFooter from "@/components/JfFooter.vue";
import JfHeader from "@/components/JfHeader.vue";

export default {
  data() {
    return {
      viewstyle: "Order",
      queryInfo: {
        pagenum: 1,
        pagesize: 10,
      },
      receiverInfo: {},
      total: 0,
      orderlist: [],
      searchID: "",
    };
  },
  created() {
    this.getOrderList(1);
  },
  methods: {
    async getOrderList(index) {
      const loading = this.$loading({
        lock: true,
        text: "Loading",
        spinner: "el-icon-loading",
        background: "rgba(0, 0, 0, 0.2)",
      });
      const { data: res } = await this.$axios.get(
        "order/my?pagenum=" + index + "&pagesize=10",
        {}
      );
      console.log(res);
      if (res.meta.status == 200) {
        this.total = res.data.total;
        this.orderlist = res.data.items;
        loading.close();
      } else if (res.meta.status == 501) {
        this.$router.push("login");
        loading.close();
        return this.$message.error("请先登录！");
      } else {
        this.$message({ message: res.meta.msg, type: "error" });
        loading.close();
      }
    },
    handleSizeChange(newSize) {
      this.queryInfo.pagesize = newSize;
      this.getOrderList();
    },
    handleCurrentChange(newPage) {
      this.queryInfo.pagenum = newPage;
      this.getOrderList(newPage);
    },
    // 展示修改地址的对话框
    showBox() {
      this.addressVisible = true;
    },
    addressDialogClosed() {
      this.$refs.addressFormRef.resetFields();
    },
    async handleSearchID() {
      // cart/:goodsId
      const { data: res } = await this.$axios.get("cart/", {});
      console.log(res);
    },
    // 支付
    async handlePay(orderSn, payPrice) {
      console.log(orderSn + "," + payPrice);
      window.open(
        "http://42.194.142.165:8088/front/mi/api/pay/order?orderSn=" +
          orderSn +
          "&payPrice=" +
          payPrice,
        "_blank"
      );
      window.close();
    },
  },
  components: {
    JfFooter,
    JfHeader,
  },
};
</script>

<style scoped>
.t_body {
  background-color: rgb(238, 238, 238);
}
</style>
